//
//  PowerBelongTableViewCell.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/6/23.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "PowerBelongTableViewCell.h"
#import "UIImage+GIF.h"
#import "GetQRCodeViewController.h"

@interface PowerBelongTableViewCell ()
{
    
}
@property (nonatomic,strong) PowerModel *myModel;
@end

@implementation PowerBelongTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)showDataWithModel:(PowerModel *)model{
    _myModel = model;
    _labelNameReal.text = [BGFunctionHelper isNULLOfString:model.name] ? @"" : model.name;
    
    
    _labelTimes.text = [NSString stringWithFormat:@"%ld",model.total_charging_count.integerValue + model.today_use_num.integerValue];
    
    _labelDays.text = [NSString stringWithFormat:@"%ld",model.total_online_count.integerValue];
    
    _labelCodeReal.text = [BGFunctionHelper isNULLOfString:model.alias] ? @"" : model.alias;
    
    _labelVersonReal.text = [BGFunctionHelper isNULLOfString:model.firmware_version] ? @"" : model.firmware_version;
    
//    _labelDateLeft.text = @"上次使用时间:";

    

    
    if (model.device_type.integerValue == 1) {//wifi充电宝
        _labelPowerReal.text = [NSString stringWithFormat:@"%ld%%",model.dump_energy.integerValue];

//        _labelDays.hidden = NO;
//        _labelDaysLeft.hidden = NO;
//        
//        _labelVerson.hidden = NO;
//        _labelVersonReal.hidden = NO;
        
        //右边图片是否隐藏
        _imageViewStatus.hidden = NO;
        if (model.green_light_status.integerValue == 0) {//已关闭
            _imageViewStatus.image = [UIImage imageNamed:@"guanbi"];
        }else if (model.green_light_status.integerValue == 1){//闪烁
            NSString *path = [[NSBundle mainBundle] pathForResource:@"shanshuo" ofType:@"gif"];
            NSData *data = [NSData dataWithContentsOfFile:path];
            UIImage *image = [UIImage sd_animatedGIFWithData:data];
            _imageViewStatus.image = image;
        }else{//常亮
            
            _imageViewStatus.image = [UIImage imageNamed:@"changliang"];
        }
        
        
        if (model.on_line.integerValue == 0) {//未激活
            _imageViewType.image = [UIImage imageNamed:@"28_WiFi02"];
        }else{
            _imageViewType.image = [UIImage imageNamed:@"28_WiFi"];
        }
        
        if (model.on_line.integerValue == 0) {//不在线
            _imageViewDate.image = [UIImage imageNamed:@"xiaxianshijian"];
//            _labelDateLeft.text = @"离线时间:";
            _labelDate.text = model.offline_time;
        }else{
//            _labelDateLeft.text = @"上线时间:";
            _imageViewDate.image = [UIImage imageNamed:@"shangxianshijian"];
            _labelDate.text = model.online_time;
        }
        
    }else{//密码充电宝
        _labelDays.text = [NSString stringWithFormat:@"%ldmA",model.today_use_num.integerValue * 1000];
        _labelDaysLeft.text = @"今日耗电:";

        _labelVerson.text = @"设备电量:";
        _labelVersonReal.text = @"15000mA";
        
        _labelPower.text = @"今日使用:";
        _labelPowerReal.text = [NSString stringWithFormat:@"%ld",model.today_use_num.integerValue];

        //右边图片是否隐藏
        _imageViewStatus.hidden = YES;
        
        _imageViewType.image = [UIImage imageNamed:@"28_mimasuo"];

        _imageViewDate.image = [UIImage imageNamed:@"28_shijian"];
        NSString *dateString ;
        if ([BGFunctionHelper isNULLOfString:model.last_use_time]) {
            dateString = @"该设备还未被使用";
        }else{
            dateString = model.last_use_time;
        }
        _labelDate.text = dateString;
    }
    
    _labelZhangFen.text = [NSString stringWithFormat:@"%ld",model.sub_count.integerValue];
}

//点击二维码
- (IBAction)GetQRCodeButtonClick:(UIButton *)sender {
    NSString *wifiCode = @"https://www.wacdd.com/rd/device/";
    NSString *mimaCode = @"https://www.wacdd.com/rd/device_pwd/";
    NSString *resaultCode;

    if (_myModel.device_type.integerValue == 1) {
        resaultCode = [NSString stringWithFormat:@"%@%@",wifiCode,_myModel.alias];
    }else{
        resaultCode = [NSString stringWithFormat:@"%@%@",mimaCode,_myModel.alias];
    }
    [_delegate clickPowerInfoAboutResaultCode:resaultCode alias:_myModel.alias];
    

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
